package com.woniuxy.consume;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

//开启注册中心默认是加上的，可加可不加
@EnableDiscoveryClient

@SpringBootApplication
@EnableFeignClients //开启Feign调用
public class ConsumeApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumeApplication.class,args);
    }

    //产生bean
//    @Bean
//    public RestTemplate restTemplate(){
//        return new RestTemplate(); //产生bean
//    }

    //第二种方法创建
    @Bean
    @LoadBalanced //开启负载均衡
    public RestTemplate restTemplate(RestTemplateBuilder builder){
        return builder.build();  //建造者产生bean
    }

    //负载均衡算法,全局的配置：所有的调用都是统一使用全局配置的负载均衡算法
//    @Bean
    public IRule myRule(){
        return new RetryRule();//轮询
    }
}
